package com.jblv.frame.common.controller;

import com.jblv.frame.common.enums.ExceptionEnum;
import com.jblv.frame.common.message.Result;
import com.jblv.frame.common.type.BooleanType;
import com.jblv.frame.common.enums.ResultCodeEnum;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author happyonion.yangtao
 * @version 1.0
 * @title BaseController
 * @projectName jblv-frame
 * @packageName com.jblv.common.controller
 * @description 基本公共控制层
 * @date Create at 2020/4/28 22:47
 * @since jdk1.8
 */
public class BaseController {

    public static <T> Result<T> renderHeaderError() {
        Result<T> result = new Result();
        result.setStatus(0);
        result.setCode(ExceptionEnum.REQUEST_HEAD_ERROR.getCode());
        result.setMessage(ExceptionEnum.REQUEST_HEAD_ERROR.getMessage());
        return result;
    }

    public static <T> Result<T> unloginInvalid() {
        Result<T> result = new Result();
        result.setStatus(0);
        result.setCode(ExceptionEnum.USER_NOT_LOGIN_ERROR.getCode());
        result.setMessage(ExceptionEnum.USER_NOT_LOGIN_ERROR.getMessage());
        return result;
    }


    public static <T> Result<T> tokenExpired() {
        Result<T> result = new Result();
        result.setStatus(0);
        result.setCode(ExceptionEnum.USER_TOKEN_EXPIRE.getCode());
        result.setMessage(ExceptionEnum.USER_TOKEN_EXPIRE.getMessage());
        return result;
    }



    public static <T> Result<T> renderError(ResultCodeEnum code) {
        Result<T> result = new Result<T>();
        result.setStatus(BooleanType.FALSE.getCode());
        result.setCode(code.getCode());
        return result;
    }

    public static  Result renderSuccess(String content) {
        Result result = new Result();
        result.setStatus(BooleanType.TRUE.getCode());
        result.setData(content);
        result.setCode(ResultCodeEnum.SUCCESS_CODE.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS_CODE.getMessage());
        return result;
    }

    public static <T> Result<T> renderSuccess(T content) {
        Result<T> result = new Result();
        result.setStatus(BooleanType.TRUE.getCode());
        result.setData(content);
        result.setMessage(ResultCodeEnum.SUCCESS_CODE.getMessage());
        return result;
    }

}
